Field of the Invention
This invention relates generally to the field of computer processors. More particularly, the invention relates to an apparatus and method for implementing flexible finite differences in a graphics processor unit (GPU).
Description of the Related Art
Pixel shaders (sometimes referred to as “fragment shaders”), compute color and other attributes of each pixel in a graphics processor unit (GPU). GPUs typically run pixel shading on 2×2 pixel quads, packing multiple such quads into one single instruction multiple data (SIMD) batch. It often happens that one or more pixels in a quad lie outside the rasterized primitive. Such pixels are referred to as “helper” pixels. The primary need for helper pixels is for gradient computation by finite differencing, i.e., taking the difference between nearby pixels horizontally and vertically to estimate the rate at which a variable changes.
Gradients are required for the level of detail (LOD) computation in texture lookups, and also for certain shared instructions (e.g., such as ddx/ddy). However, helper pixels contribute in no other way to the visible image. Since shading helper pixels consumes valuable resources (power, bandwidth, and compute), it is desirable to find less expensive ways to compute gradients. The number of helper pixels in quad-based pixel shading can be substantial, often in the range of 40-50% or more of the total shaded pixels. Additionally, the problem of helper pixels is amplified for smaller triangles, and/or with the use of larger shading quads (i.e. coarse pixel shading (CPS)).